
function basic_split(str)
{
	if(str=="")return [];
	var basic = str.split("\n");

	return basic;
}
/*
function basic_parse(str, i, token, mode)
{

	if (mode === BASIC_GET_UNTIL)
	{
		var n = i;
		var temp = "";
		while (str[n] != token)
		{
			temp += str[n];
			n++;
		}
		return temp;
	}
	else
	{
		console.warn("basic_parse() mode参数错误");
	}

}
*/
function basic_exec(arr)
{	
	console.log(arr);
	if(arr.length==0)return;
	console.log("basic_exec 在", $GLOBAL_BASIC_LINE, "解析")
	var str = arr[$GLOBAL_BASIC_LINE];
	var code = str.split(",");
	console.log(code)
	if (isNaN(code[0]) === true)
	{
		console.warn("basic_exec 在", $GLOBAL_BASIC_LINE, "行：无行号");
		code.unshift("0")
			console.log(code)
		}
		
		if (code[1] == "jump")
		{
			/*
			01 jump imm
			跳转到imm位置
			 */
			 $GLOBAL_BASIC_LINE=parseInt(code[2]) -1;
			basic_exec(arr);
			
		}
		else if (code[1] == "jumpif")
		{
			/*
			02 jumpif cond imm
			跳转到imm位置如果cond被满足
			 */
			 console.log(basic_eval(code[2]))
			if (basic_eval(code[2]))
			{
			 $GLOBAL_BASIC_LINE=parseInt(code[3]) -1;
			basic_exec(arr);
			}
			else
			{
			$GLOBAL_BASIC_LINE++;
			basic_exec(arr);
			}
		}
		else if (code[1] == "assign")
		{
			/*
			03 assign var value
			将value赋值到var中
			 */
			
			eval(code[2]+" = "+basic_eval(code[3]));
			 $GLOBAL_BASIC_LINE++;
			basic_exec(arr);
		}
		else if (code[1] == "input")
		{
			/*
			04 input var tip
			提示tip并且将输入的内容存到var中
			 */
			var temp_string="";
			for(var i=3;i<code.length;i++)temp_string+=basic_eval(code[i]);
			console.log(temp_string);
			eval(code[2] +"=prompt(\""+temp_string+"\")");
			$GLOBAL_BASIC_LINE++;
			basic_exec(arr);

		}
		else if (code[1] == "output")
		{
			/*
			05 output exp
			将exp解释并输出
			 */
			 document.getElementById("cName").innerHTML = "";
			 document.getElementById("Dlg").innerHTML="";
			 for(var i=2;i<code.length;i++)
			document.getElementById("Dlg").innerHTML += basic_eval(code[i]);
			
			//alert(basic_eval(code[2]))
		}
		else if (code[1] == "address")
		{
			/*
			06 address script
			跳转到script剧本
			 */
			 jqxx_TiaoZhuan('?dialogue='+code[2]);

		}
		else if (code[1] == "halt")
		{
			console.log("halt")
			$GLOBAL_BASIC_FLAG=false;
			return;
		}
		else
		{
			$GLOBAL_BASIC_FLAG =false;
			console.warn("basic_exec 在", $GLOBAL_BASIC_LINE, "行：语法错误")
			return;
		}

	}



function basic_eval(exp)
{
	
		console.log(exp)
		return (eval(exp))
}
